//
//  CommonRequestManager.m
//  TrainTree
//
//  Created by wanghui on 2017/9/28.
//  Copyright © 2017年 YouYeShu. All rights reserved.
//

#import "CommonRequestManager.h"
#import "CarouselModel.h"
@implementation CommonRequestManager

+ (void)getBannerListResponse:(ResponseData)responseBlock// modelDataBlock:(ModelData)modelBlock;
{
    RequestParam *param = [[RequestParam alloc]init];
    [param setRequestPath:TrainTreeBannerListURL];
    [[HttpClient shareInstanceClient] GetReqeustParameter:param response:^(id JSONData, NSError *error, NSURLSessionDataTask *dataTask) {
        if (error.code == -1001) {
            NSLog(@"请求超时11");
        }
        if (JSONData) {
            if ([JSONData[@"c"] intValue] == 0) {
                NSArray *bannerArray = JSONData[@"d"];
                NSMutableArray *tmpArray = [[NSMutableArray alloc]init];
                for (NSDictionary *dic in bannerArray) {
                    CarouselModel *model = [[CarouselModel alloc]init];
                    model.bannerId = dic[@"id"] ?: @"1";
                    model.imageUrl = dic[@"image"] ?: @"1";
                    model.targetUrl = dic[@"target"] ?: @"1";
                    model.type = dic[@"type"] ?: @"1";
                    model.lessonName = dic[@"lessonName"];
                    model.moduleName = dic[@"moduleName"];
                    model.themeName  = dic[@"themeName"];

                    [tmpArray addObject:model];
                }

                NSArray *arry = [tmpArray copy];
                [BannerData shareBannerData].bannerArray = arry;
                [[NSNotificationCenter defaultCenter]postNotificationName:@"reloadDataWithSlideshow" object:@YES];
//                [[BannerData shareBannerData] saveBannerData:JSONData];
                responseBlock(JSONData,error,dataTask);
            }
        } else {
            [SVProgressHUD showErrorWithStatus:@"获取轮播图失败，请检查网络"];
        }
    }];
}
@end
